package com.s08.h01.model;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public abstract class User extends Object {

	private String name;
	private String surname;
	private Address address;
	private List<Product> cart = new ArrayList<>();

	public User(String name, String surname) {
		setName(name);
		setSurname(surname);
	}

	public User(Object object) {
		setName(name);
		setSurname(surname);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public void process() {
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public List<Product> getCart() {
		return cart;
	}

	public void setCart(List<Product> cart) {
		this.cart = cart;
	}

	@Override
	public String toString() {
		return "User " + name + " "+ surname;
	}

	public String showProducts() {

		List<Product> products = getCart();
		String result = "";

		
		for (Product product : products) {
			if (product != null)
				result += "Products :"+ product.getClass().getSimpleName() +" "+ product.showPrice() + "$"
						+ System.getProperty("line.separator");
		}
		return result;

	}

	public String showDiscountedProducts() {

		BigDecimal decimalDiscountPercent = new BigDecimal(Double.toString(0.1));
		
		
		List<Product> products = getCart();
		String result = "";

		for (Product product : products) {
			if (product != null){
		BigDecimal discountAmount = product.getPrice().multiply(decimalDiscountPercent);
		 
		BigDecimal discountedProduct=product.getPrice().subtract(discountAmount);		
		product.setPrice(discountedProduct);
		
		
		result += "Products :"+ product.getClass().getSimpleName() +" "+ product.showPrice() + "$"
				+ System.getProperty("line.separator");
		
			}
		}
		
		return result;


	}

}
